package com.winsun.hellozookeeper.server;

import com.winsun.hellozookeeper.service.HelloService;
import com.winsun.hellozookeeper.service.impl.HelloServiceImpl;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.rmi.registry.LocateRegistry;

public class Server {
    private String serverHost;

    public Server(String serverHost) {
        this.serverHost = serverHost;
        try {
            //在本机上创建和导出注册表实例并在指定的端口上接受请求
            LocateRegistry.createRegistry(1888);
            //创建远程对象
            HelloService helloService=new HelloServiceImpl();
            //初始化命名内容
            Context context= new InitialContext();
            //注册对象
            context.rebind("rmi://"+serverHost+":1888/helloService",helloService);
            System.out.println("服务已启动");


        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        new Server("192.168.85.117");
    }
}
